﻿using System;
using System.Collections.Generic;

namespace Minecraft.Model.AchievementItem
{
	/// <summary>
	/// 
	/// </summary>
	public class ModAchievementItemInfo
	{
		/// <summary>
		/// 成就的id
		/// </summary>
		public int AchievementId { get; set; }
		/// <summary>
		/// 此成就中已达到的 玩家级数、已击杀的怪物数、已解锁的蓝图数、已与玩家联机的次数。。。
		/// </summary>
		public int FinishedNum { get; set; }
		/// <summary>
		/// 0未领，1已领
		/// </summary>
		public int AwardGot { get; set; }
		/// <summary>
		/// 枚举，0成就未开始，1进行中，2已完成
		/// </summary>
		public EnumAchievementStatus Status { get; set; }


		/// <summary>
		/// 
		/// </summary>
		/// <param name="str"></param>
		/// <returns></returns>
		public static List<ModAchievementItemInfo> ConvertStr2List(string str)
		{
			if (string.IsNullOrEmpty(str))
			{
				return null;
			}
			var achievementStrList = str.Split('|');
			List<ModAchievementItemInfo> achievementItemList = new List<ModAchievementItemInfo>();
			for (var i = 0; i < achievementStrList.Length; i++)
			{
				var t = achievementStrList[i];
				var temp = new ModAchievementItemInfo
				{
					AchievementId = int.Parse(t.Split('#')[0]),
					FinishedNum = int.Parse(t.Split('#')[1]),
					AwardGot = int.Parse(t.Split('#')[2]),
					Status = (EnumAchievementStatus)Enum.Parse(typeof(EnumAchievementStatus), t.Split('#')[3], true)
				};
				achievementItemList.Add(temp);
			}

			return achievementItemList;
		}

	}
}
